import tensorflow as tf

print(tf.__version__)

#  使用tf.keras 实现简单线性回归
import pandas as pd

data = pd.read_csv("../dataset/credit-a.csv", header=None)
print(data.head(2))
print(data.iloc[:, -1].value_counts())
x = data.iloc[:, :-1]
y = data.iloc[:, -1].replace(-1, 0)

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(4, activation='relu', input_shape=(15,)))
model.add(tf.keras.layers.Dense(4, activation='relu'))
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))

model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.1),
              loss='binary_crossentropy',
              metrics=['acc'])
history = model.fit(x, y, epochs=100)
print(history.history.keys())
import matplotlib.pyplot as plt
plt.plot( history.epoch , history.history.get('loss'))
plt.show()

plt.plot( history.epoch , history.history.get('acc'))
plt.show()
